import req from '../utils/request';
import * as URL from '../constans/api';
// 账号登录
export function login(params) {
  return req({
    url: URL.LOGIN,
    method: 'post',
    data: params,
  })
    .then((res) => {
      localStorage.setItem('userInfo', JSON.stringify(res.data.result));
      console.log('11', res.data);
      return res.data;
    })
    .catch((err) => {
      console.log('444', err);
      Promise.reject(err.response.data);
    });
}
// 短信登录
export function codeLogin(params) {
  return req({
    url: URL.CODE_LOGIN,
    method: 'post',
    data: params,
  })
    .then((res) => {
      localStorage.setItem('userInfo', JSON.stringify(res.data.result));
      console.log(res.data);
      return res.data;
    })
    .catch((err) => Promise.reject(err.response.data));
}
// 获取验证码
export function getCode(params) {
  return req({
    url: URL.CODE,
    method: 'get',
    params,
  })
    .then((res) => {
      console.log(res.data);
      return res.data;
    })
    .catch((err) => Promise.reject(err.response.data));
}
